﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;

namespace BLL
{
    public class LabelBLL
    {
        public List<LabelSP> GetAll()
        {
            using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
            {
                return data.LabelSPs.OrderBy(p => p.Name).ToList();
            }
        }

        public LabelSP GetById(int id)
        {
            using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
            {
                return data.LabelSPs.Where(p => p.Id == id).FirstOrDefault();
            }
        }


        public void Add(LabelSP obj)
        {
            using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
            {
                data.LabelSPs.InsertOnSubmit(obj);
                data.SubmitChanges();
            }
        }
        public void Update(LabelSP label)
        {
            using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
            {
                LabelSP obj = data.LabelSPs.Where(p => p.Id == label.Id).FirstOrDefault();
                if (obj != null)
                {
                    obj.Name = label.Name;
                    obj.Color = label.Color;
                }
                data.SubmitChanges();
            }
        }
        public void Delete(int id)
        {
            using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
            {
                LabelSP obj = data.LabelSPs.Where(p => p.Id == id).FirstOrDefault();
                if (obj != null)
                {
                    data.LabelSPs.DeleteOnSubmit(obj);
                    data.SubmitChanges();
                }
            }
        }
    }
}
